package com.ptszyxx.popose.module.main.user;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;
import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ysg.http.data.AppViewModelFactory;
import com.ptszyxx.popose.databinding.FragmentUserDetailMineBinding;
import com.ptszyxx.popose.module.main.user.adapter.UserGiftAdapter;
import com.ptszyxx.popose.module.main.user.adapter.UserLabelAdapter;
import com.ysg.http.data.entity.user.GiftEntity;
import com.ptszyxx.popose.module.main.user.vm.UserDetailMineVM;
import com.ysg.base.BaseFragment;
import com.ysg.utils.YCollectionUtil;
import com.ysg.utils.YStringUtil;
import java.util.List;

public class UserDetailMineFragment extends BaseFragment<FragmentUserDetailMineBinding, UserDetailMineVM> {
    private String userId;
    private UserGiftAdapter giftAdapter;
    private UserLabelAdapter labelAdapter;


    public UserDetailMineFragment() {}

    public UserDetailMineFragment(String userId){
        this.userId = userId;
    }

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_user_detail_mine;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public UserDetailMineVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(UserDetailMineVM.class);
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.userId = userId;
        viewModel.requestUserGift();
    }

    @Override
    public void initAdapter() {
        super.initAdapter();
        labelAdapter = new UserLabelAdapter();
        giftAdapter = new UserGiftAdapter();
        binding.refreshViewLabel.initAdapterGrid(labelAdapter, 5);
        binding.refreshViewGift.initAdapterGrid(giftAdapter, 4);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        viewModel.uc.onGiftEvent.observe(this, o -> setGiftUI((List<GiftEntity>)o));
        viewModel.uc.onLabelEvent.observe(this, o -> setLabelUI((List<String>)o));
    }
    /**
     * 标签UI
     */
    private void setLabelUI(List<String> list) {
        if (YCollectionUtil.isNotEmpty(list)){
            labelAdapter.setList(list);
        }
//        binding.refreshViewLabel.setAdapterUI(labelAdapter, list, true);
    }
    /**
     * 礼物UI
     */
    private void setGiftUI(List<GiftEntity> list) {
        binding.refreshViewGift.setAdapterUI(giftAdapter, list, true);
    }
    /**
     * 性别
     */
    public void setSexUI(Integer sex){
        viewModel.sex.set(YStringUtil.eq(2, sex)? getResources().getString(R.string.girl): getResources().getString(R.string.boy));
    }




}
